package com.huawei.secure.android.common.ssl;

import android.content.Context;
import android.util.Log;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SignatureException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.X509TrustManager;

public class f implements X509TrustManager {
    private static final String TAG = "WebViewX509TrustManger";
    private X509Certificate ab;
    private List<X509TrustManager> c = new ArrayList();

    public f(Context context) {
        if (context == null) {
            throw new NullPointerException("WebViewX509TrustManger context is null");
        }
        this.ab = new g(context).d();
        if (this.ab == null) {
            throw new NullPointerException("WebViewX509TrustManger cannot get cbg root ca");
        }
    }

    public void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) {
        Log.e(TAG, "checkClientTrusted: ");
    }

    public void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) throws CertificateException {
        CertificateException certificateException;
        Object obj = null;
        Log.e(TAG, "checkServerTrusted: ");
        X509Certificate[] x509CertificateArr2 = new X509Certificate[x509CertificateArr.length];
        for (int i = 0; i < x509CertificateArr.length; i++) {
            x509CertificateArr2[i] = x509CertificateArr[(x509CertificateArr.length - 1) - i];
        }
        CertificateException certificateException2 = new CertificateException("CBG root CA CertificateException");
        try {
            if (b.a(this.ab, x509CertificateArr2)) {
                obj = 1;
            }
            certificateException = certificateException2;
        } catch (NoSuchProviderException e) {
            Log.e(TAG, "checkServerTrusted NoSuchProviderException: " + e.getMessage());
            certificateException = certificateException2;
        } catch (NoSuchAlgorithmException e2) {
            Log.e(TAG, "checkServerTrusted NoSuchAlgorithmException: " + e2.getMessage());
            certificateException = certificateException2;
        } catch (InvalidKeyException e3) {
            Log.e(TAG, "checkServerTrusted InvalidKeyException: " + e3.getMessage());
            certificateException = certificateException2;
        } catch (SignatureException e4) {
            Log.e(TAG, "checkServerTrusted SignatureException: " + e4.getMessage());
            certificateException = certificateException2;
        } catch (CertificateException e5) {
            certificateException = e5;
            Log.e(TAG, "checkServerTrusted CertificateException: " + certificateException.getMessage());
        }
        if (obj == null) {
            throw certificateException;
        }
    }

    public X509Certificate[] getAcceptedIssuers() {
        try {
            ArrayList arrayList = new ArrayList();
            for (X509TrustManager acceptedIssuers : this.c) {
                arrayList.addAll(Arrays.asList(acceptedIssuers.getAcceptedIssuers()));
            }
            return (X509Certificate[]) arrayList.toArray(new X509Certificate[arrayList.size()]);
        } catch (Exception e) {
            Log.e(TAG, "getAcceptedIssuers exception : " + e.getMessage());
            return new X509Certificate[0];
        }
    }
}
